package com.xiaoxi.exam.job;

import com.xiaoxi.exam.service.AccountService;
import com.xiaoxi.exam.service.OrderService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.annotation.PostConstruct;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

//@Component
public class Starter {

  @Autowired
  @Lazy
  private OrderService orderService;

  @Autowired
  @Lazy
  private AccountService accountService;

  @Value("${confirm.order.url}")
  private String url;

  @Value("${ocr.url:http://localhost:8000/ocr/}")
  private String ocrUrl;

  @PostConstruct
  public void initToefleJob() {
    System.setProperty("webdriver.gecko.driver", "C:\\geckodriver.exe");
    FirefoxOptions options = new FirefoxOptions();
//    options.addArguments("--headless");
    FirefoxDriver driver = new FirefoxDriver(options);
    GetSeatOutJob job = new GetSeatOutJob(orderService, accountService, url, driver, ocrUrl);
    ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
    executorService.scheduleWithFixedDelay(job, 20, 1, TimeUnit.SECONDS);
  }


}
